/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ixj_xmlprocess;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;

/**
 *
 * @author LamHuynh
 */
public class SearchXMLSoup {
    String fileName;
    public SearchXMLSoup(String fileName){
        this.fileName = fileName;
    }
    public Boolean foundCustomerByName(String name)
    {
        //String xml = readTextFile(this.fileName);
        File f = new File(fileName);
        try{
            Document doc = Jsoup.parse(f, "UTF-8");
            Elements elements = doc.select("fname");
            String fname = elements.first().val();
            System.out.println(elements.first().val());
        }
        catch(Exception e)
        {
            String s = e.getMessage();
            int a = 1;
        }
        
        return false;
    }
    public String readTextFile(String fileName) {

          String returnValue = "";
          FileReader file = null;

          try {
            file = new FileReader(fileName);
            BufferedReader reader = new BufferedReader(file);
            String line = "";
            while ((line = reader.readLine()) != null) {
              returnValue += line + "\n";
            }
          } catch (FileNotFoundException e) {
              throw new RuntimeException("File not found");
          } catch (IOException e) {
              throw new RuntimeException("IO Error occured");
          } finally {
            if (file != null) {
              try {
                file.close();
              } catch (IOException e) {
              }
            }
          }
          return returnValue;
        }
}
